<?php
namespace app\home\controller;

use app\BaseController;
use app\libs\exception\NotFoundException;
use app\libs\exception\ParamException;
use app\libs\exception\ServerError;
use app\model\ArticleModel;
use app\model\BannerModel;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use think\Model;

class Home extends BaseController
{
    /**
     * @throws \app\libs\exception\NotFoundException
     * @throws \app\libs\exception\ServerError
     */
    public function getBanner(): \think\response\Json
    {
        $banner_list = (new BannerModel())->with('bannerImage')->select();
        return json($banner_list);
    }

    /**
     * @throws \app\libs\exception\NotFoundException
     * @throws \app\libs\exception\ServerError
     */
    public function getArticle(): \think\response\Json
    {
        $article_list = (new ArticleModel())
            ->field(['id', 'title'])
            ->select();
        return json($article_list);
    }

    /**
     * @throws NotFoundException
     * @throws ServerError
     */
    public function getArticleDetail($id): \think\response\Json
    {
        $article = (new ArticleModel())->find_add_pv($id);
        return json($article);
    }
}
